<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>photo.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
  </script>

  <script src="static/js/doc.js">
  </script>

  <meta charset="utf8">
</head>

<body onload="prettyPrint()">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_ui_media_photo.js.html">photo.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line2"></a>// you may not use this file except in compliance with the License.
<a name="line3"></a>// You may obtain a copy of the License at
<a name="line4"></a>//
<a name="line5"></a>//     http://www.apache.org/licenses/LICENSE-2.0
<a name="line6"></a>//
<a name="line7"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line8"></a>// distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
<a name="line9"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line10"></a>// See the License for the specific language governing permissions and
<a name="line11"></a>// limitations under the License.
<a name="line12"></a>
<a name="line13"></a>// Copyright 2009 Google Inc. All Rights Reserved.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview provides a reusable photo UI component that renders photos that
<a name="line17"></a> * contains metadata (such as captions, description, thumbnail/high resolution
<a name="line18"></a> * versions, etc).
<a name="line19"></a> *
<a name="line20"></a> * goog.ui.media.Photo is actually a {@link goog.ui.ControlRenderer},
<a name="line21"></a> * a stateless class - that could/should be used as a Singleton with the static
<a name="line22"></a> * method {@code goog.ui.media.Photo.getInstance} -, that knows how to render
<a name="line23"></a> * Photos. It is designed to be used with a {@link goog.ui.Control}, which will
<a name="line24"></a> * actually control the media renderer and provide the {@link goog.ui.Component}
<a name="line25"></a> * base. This design guarantees that all different types of medias will behave
<a name="line26"></a> * alike but will look different.
<a name="line27"></a> *
<a name="line28"></a> * goog.ui.media.Photo expects {@code goog.ui.media.MediaModel} on
<a name="line29"></a> * {@code goog.ui.Control.getModel} as data models.
<a name="line30"></a> *
<a name="line31"></a> * Example of usage:
<a name="line32"></a> *
<a name="line33"></a> * &lt;pre&gt;
<a name="line34"></a> *   var photo = goog.ui.media.Photo.newControl(
<a name="line35"></a> *       new goog.ui.media.MediaModel(&#39;http://hostname/file.jpg&#39;));
<a name="line36"></a> *   photo.render(goog.dom.$(&#39;parent&#39;));
<a name="line37"></a> * &lt;/pre&gt;
<a name="line38"></a> *
<a name="line39"></a> * Photo medias currently support the following states:
<a name="line40"></a> *
<a name="line41"></a> * &lt;ul&gt;
<a name="line42"></a> *   &lt;li&gt; {@link goog.ui.Component.State.HOVER}: mouse cursor is over the photo.
<a name="line43"></a> *   &lt;li&gt; {@link goog.ui.Component.State.SELECTED}: photo is being displayed.
<a name="line44"></a> * &lt;/ul&gt;
<a name="line45"></a> *
<a name="line46"></a> * Which can be accessed by
<a name="line47"></a> *
<a name="line48"></a> * &lt;pre&gt;
<a name="line49"></a> *   photo.setHighlighted(true);
<a name="line50"></a> *   photo.setSelected(true);
<a name="line51"></a> * &lt;/pre&gt;
<a name="line52"></a> *
<a name="line53"></a> */
<a name="line54"></a>
<a name="line55"></a>goog.provide(&#39;goog.ui.media.Photo&#39;);
<a name="line56"></a>
<a name="line57"></a>goog.require(&#39;goog.ui.media.Media&#39;);
<a name="line58"></a>goog.require(&#39;goog.ui.media.MediaRenderer&#39;);
<a name="line59"></a>
<a name="line60"></a>
<a name="line61"></a>/**
<a name="line62"></a> * Subclasses a goog.ui.media.MediaRenderer to provide a Photo specific media
<a name="line63"></a> * renderer. Provides a base class for any other renderer that wants to display
<a name="line64"></a> * photos.
<a name="line65"></a> *
<a name="line66"></a> * This class is meant to be used as a singleton static stateless class, that
<a name="line67"></a> * takes {@code goog.ui.media.Media} instances and renders it.
<a name="line68"></a> *
<a name="line69"></a> * This design is patterned after
<a name="line70"></a> * http://go/closure_control_subclassing
<a name="line71"></a> *
<a name="line72"></a> * @constructor
<a name="line73"></a> * @extends {goog.ui.media.MediaRenderer}
<a name="line74"></a> */
<a name="line75"></a>goog.ui.media.Photo = function() {
<a name="line76"></a>  goog.ui.media.MediaRenderer.call(this);
<a name="line77"></a>};
<a name="line78"></a>goog.inherits(goog.ui.media.Photo, goog.ui.media.MediaRenderer);
<a name="line79"></a>goog.addSingletonGetter(goog.ui.media.Photo);
<a name="line80"></a>
<a name="line81"></a>
<a name="line82"></a>/**
<a name="line83"></a> * Default CSS class to be applied to the root element of components rendered
<a name="line84"></a> * by this renderer.
<a name="line85"></a> *
<a name="line86"></a> * @type {string}
<a name="line87"></a> */
<a name="line88"></a>goog.ui.media.Photo.CSS_CLASS = goog.getCssName(&#39;goog-ui-media-photo&#39;);
<a name="line89"></a>
<a name="line90"></a>
<a name="line91"></a>/**
<a name="line92"></a> * A static convenient method to construct a goog.ui.media.Media control out of
<a name="line93"></a> * a photo {@code goog.ui.media.MediaModel}. It sets it as the data model
<a name="line94"></a> * goog.ui.media.Photo renderer uses, sets the states supported by the renderer,
<a name="line95"></a> * and returns a Control that binds everything together. This is what you
<a name="line96"></a> * should be using for constructing Photos, except if you need finer control
<a name="line97"></a> * over the configuration.
<a name="line98"></a> *
<a name="line99"></a> * @param {goog.ui.media.MediaModel} dataModel The photo data model.
<a name="line100"></a> * @return {goog.ui.media.Media} A goog.ui.Control subclass with the photo
<a name="line101"></a> *     renderer.
<a name="line102"></a> */
<a name="line103"></a>goog.ui.media.Photo.newControl = function(dataModel) {
<a name="line104"></a>  var control = new goog.ui.media.Media(
<a name="line105"></a>      dataModel,
<a name="line106"></a>      goog.ui.media.Photo.getInstance());
<a name="line107"></a>  return control;
<a name="line108"></a>};
<a name="line109"></a>
<a name="line110"></a>
<a name="line111"></a>/**
<a name="line112"></a> * Creates the initial DOM structure of a photo.
<a name="line113"></a> *
<a name="line114"></a> * @param {goog.ui.media.Media} control The media control.
<a name="line115"></a> * @return {Element} A DOM structure that represents the control.
<a name="line116"></a> */
<a name="line117"></a>goog.ui.media.Photo.prototype.createDom = function(control) {
<a name="line118"></a>  var div = goog.ui.media.Photo.superClass_.createDom.call(this, control);
<a name="line119"></a>
<a name="line120"></a>  var img = control.getDomHelper().createDom(&#39;img&#39;, {
<a name="line121"></a>    src: control.getDataModel().getPlayer().getUrl(),
<a name="line122"></a>    className: goog.getCssName(this.getCssClass(), &#39;image&#39;)
<a name="line123"></a>  });
<a name="line124"></a>
<a name="line125"></a>  div.appendChild(img);
<a name="line126"></a>
<a name="line127"></a>  return div;
<a name="line128"></a>};
<a name="line129"></a>
<a name="line130"></a>
<a name="line131"></a>/**
<a name="line132"></a> * Returns the CSS class to be applied to the root element of components
<a name="line133"></a> * rendered using this renderer.
<a name="line134"></a> * @return {string} Renderer-specific CSS class.
<a name="line135"></a> */
<a name="line136"></a>goog.ui.media.Photo.prototype.getCssClass = function() {
<a name="line137"></a>  return goog.ui.media.Photo.CSS_CLASS;
<a name="line138"></a>};
</pre>


</body>
</html>
